package com.eff.android.fragment;

import com.eff.android.EMainActivity;
import com.eff.android.R;

import android.app.ActionBar;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class EBaseFragment extends Fragment{
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		View v = onCreateActionBarView(getActivity().getLayoutInflater());
		if (v != null) {
		    getActivity().getActionBar().setCustomView(v, getLayoutParams());
		}
	}

	protected View onCreateActionBarView(LayoutInflater inflater) {
    	return inflater.inflate(R.layout.e_actionbar_default, null);
    }

    public void onActionBarViewClicked(View v) {
    }

    private ActionBar.LayoutParams getLayoutParams() {
	ActionBar.LayoutParams params = new ActionBar.LayoutParams(
		ActionBar.LayoutParams.MATCH_PARENT,
		ActionBar.LayoutParams.MATCH_PARENT, Gravity.CENTER);
	return params;
    }

    protected void switchFragment(Fragment f, String tagName) {
		if (getActivity() != null) {
		    ((EMainActivity) getActivity()).setupContentFragment(f, tagName, true);
		}
    }

    @Override
    public void onDestroyView() {
		super.onDestroyView();
		Runtime.getRuntime().gc();
		System.gc();
		View container = getView();
		if (container != null) {
		    ViewGroup group = (ViewGroup) container.getParent();
		    if (group != null) {
			group.removeAllViewsInLayout();
		    }
		}
    }
}
